﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using IDal;
using Model;

namespace Dal
{
    public class DbContextFactory:IDbContextFactory
    {
        /// <summary>
        /// 获取EF访问上下文对象
        /// </summary>
        /// <returns></returns>
        public System.Data.Entity.DbContext GetDbContext()
        {
            //在线程中共享一个上下文对象
            DbContext dbContext = CallContext.GetData(typeof(DbContextFactory).Name) as DbContext;
            if (dbContext==null)
            {
                dbContext=new OuOAEntities();
                CallContext.SetData(typeof(DbContextFactory).Name, dbContext);
            }
            return dbContext;
        }
    }
}
